<template>
	<contents :heightInclude="['tabBar']" class="settings_page">
		<u-cell-group>
			<u-cell-item
				@click="
					navSwitch(
						'/pages/user/settings/setMobile?mobile=' +
							userInfo.mobile || ''
					)
				"
				:title="$t('locales.setPhone')"
				:value="userInfo.mobile || $t('locales.setPhoneTielt')"
			></u-cell-item>
			<u-cell-item
				@click="
					navSwitch(
						'/pages/user/settings/setUserName?nickName=' +
							userInfo.nickname || ''
					)
				"
				:title="$t('locales.setNikeName')"
				:value="userInfo.nickname || $t('locales.setNikeNameTitle')"
			></u-cell-item>
			<u-cell-item
				@click="
					navSwitch(
						`/pages/user/forgetPassword/index?mobile=${userInfo.mobile == '' ? userInfo.email : userInfo.mobile}`
					)
				"
				:title="$t('locales.loginPwd')"
				:value="$t('locales.loginPwdTitle')"
			></u-cell-item>
			<u-cell-item
				@click="
					navSwitch(
						'/pages/user/settings/setPaymentPassword?mobile=' +
							userInfo.mobile || ''
					)
				"
				:title="$t('locales.paymentPwd')"
				:value="$t('locales.paymentPwdTitle')"
			></u-cell-item>
			<!-- #ifdef H5 -->
			<u-cell-item
				@click="
					navSwitch(
						'/pages/user/settings/commonSites'
					)
				"
				:title="$t('locales.commonSites')"
				:value="$storage.get('site') ? $storage.get('site').siteName : $t('locales.commonSitesTips')"
			></u-cell-item>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS -->
			<u-cell-item
				@click="
					navSwitch(
						'/pages/user/settings/commonSites'
					)
				"
				:title="$t('locales.commonSites')"
				:value="$storage.get('site') ? $storage.get('site').siteName : $t('locales.commonSitesTips')"
			></u-cell-item>
			<!-- #endif -->
			<u-cell-item
				@click="
					navSwitch(
						'/pages/user/settings/switchLanguage'
					)
				"
				:title="$t('locales.switchLanguage')"
				:value="this.$storage.get('languageName') ? this.$storage.get('languageName') : $t('locales.followingSystem')"
			></u-cell-item>
			<u-cell-item
				@click="loginOut"
				:title="$t('locales.logOut')"
				:value="$t('locales.loginOut')"
			></u-cell-item>
		</u-cell-group>
	</contents>
</template>

<script>
export default {
	data() {
		return {
			userInfo: {
				nickname: '',
				mobile: ''
			}
		}
	},
	onLoad() {
		this.getData()
	},
	onShow() {
		this.getData()
	},
	onPullDownRefresh() {
		this.getData()
		uni.stopPullDownRefresh()
	},
	methods: {
		getData() {
			this.$store.dispatch('UserInfo').then(res => {
				this.userInfo = res
			})
		},
		navSwitch(url) {
			console.log(url)
			uni.navigateTo({
				url
			})
		},
		loginOut() {
			this.$store.dispatch('LoginOut').then(() =>
				uni.reLaunch({
					url: '/pages/index/home/index'
				})
			)
		}
	}
}
</script>

<style lang="scss" scoped></style>
